from java.lang import String
from java.io import File
from java.util import Locale
from java.awt import *

from jscinttools.scint import *
from jscinttools.scint.coincidence import *
from jscinttools.utilities.scintutilities import ScintUtil

Locale.setDefault(Locale.ENGLISH)
#System.getProperties().setProperty("hep.aida.BatchAnalysisFactory","hep.aida.ref.BatchAnalysisFactory")
#af = IAnalysisFactory.create();

showFigures = False
writeFigures = not showFigures

""" Define colors and fonts"""
figType = [".png", ".eps"]
colors = [Color.blue, Color.red, Color(0, 170, 0), Color.black, Color.yellow]
axisLabelFont = Font(Font.SERIF, Font.PLAIN, 25)
titleFont = Font(Font.SERIF, Font.PLAIN, 25)
legendFont = Font(Font.SERIF, Font.PLAIN, 25)
ticFont = Font(Font.SERIF, Font.PLAIN, 20)
statBoxFont = Font(Font.SERIF, Font.PLAIN, 15)


""" Define the Path and files names"""
#aidaPath = "/home/marc-antoine/Documents/jCode/Dropbox/CryoDAQ/Reduced_Data/2011_03_28/"
aidaPath = "/home/marc-antoine/Documents/BGO/QFin/"
aidaFile = "ScintillationAnalysis_BGO"
outPath = "/home/marc-antoine/Dropbox/BGO"


"""299 K"""
#specFile = "/home/marc-antoine/Documents/BGO/2009_03_21/CP1824_NC60_PM_Vpol1050_1000_BGO_22Na2kBq_Ampl_Coinc2us_CoincNCBGO_Coinc2us_FanOut_SciCryo_299K_PhotonReanalysis_NoTuples"
#title = "BGO  with ^{22}Na at 299 K"
#amp = [0.730, 0.35]
#tau = [0.055, 0.374]
#tCoinc = 2.0
#rangeX = [0, 50]
#specOutFile = "CoincEff299K"

"""30 K"""
#specFile = "/home/marc-antoine/Documents/BGO/2009_03_05/CP1824_NC60_PM_Vpol1050_1000_BGO_22Na2kBq_Ampl_Coinc2us_CoincNCBGO_Coinc2us_FanOut_SciCryo_30K_PhotonReanalysis_NoTuples"
#title = "BGO  with ^{22}Na at 30 K"
#amp = [0.8]
#tau = [22.8]
#tCoinc = 2.0
#rangeX = [0, 200]
#specOutFile = "CoincEff30K"

"""3 K"""
specFile = "/home/marc-antoine/Documents/BGO/2009_03_03/CP1824_NC60_PM_Vpol1050_1000_BGO_22Na2kBq_Ampl_Coinc2us_CoincNCBGO_Coinc2us_FanOut_SciCryo_3K_PhotonReanalysis_NoTuples"
title = "BGO  with ^{22}Na at 3 K"
amp = [0.67, 0.30, 0.1]
tau = [0.89, 145.5, 435]
tCoinc = 2.0
rangeX = [0, 200]
specOutFile = "CoincEff3K"


ly = []
for i in range(len(tau)):
	ly.append(ScintUtil.calcLYFrac(i, amp, tau))



spectrum = Spectrum(specFile).getSpectrum()
spectrum.color = colors[0]
spectrum.style = "h"
spectrum.penWidth = 2
spectrum.errAll = False

coincEff = CoincEfficiency(ly, tau, tCoinc).photCoincEfficiency(MultiCompCoincProba())
coincEff.setMin(spectrum.getMin())
coincEff.setMax(spectrum.getMax())
coincEff.setPoints(10000)
coincEff.color = colors[1]
coincEff.penWidth = 2


plotter = PhotonCoincEffPlotter(title, spectrum, coincEff).photonCoincEffPlotter(rangeX)
if showFigures:
	plotter.visible(True)
else:
	plotter.visible(False)
	for i in range(len(figType)):
		plotter.export(outPath + File.separator + specOutFile + figType[i])
		print("Writting File : " + outPath + File.separator + specOutFile + figType[i])


print("That's all folks !")

